/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.javatrainning.hieptq.b2;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Hiep
 */
public class TryCatch {
     public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = 0;
        int t = 0;
        while (t == 0) {
            t = 1;
            try {

                k = Integer.parseInt(sc.nextLine());
                if (k < 0) {
                    throw new Exception("nhap lai phai lon hon 0");
                }
            } catch (NullPointerException e) {
                System.out.println("nhap sai phai nhap gia tri nhap lai");
                t = 0;
            } catch (NumberFormatException e) {
                System.out.println("nhap sai phai nhap vao so nhap lai");
                t = 0;
            } catch (Exception e) {
                System.out.println(e);
                t = 0;
            }
        }
        t = 0;
        System.out.println(k);
        String s;
        int m = 0;
        while (t == 0) {
            t = 1;
            s = sc.nextLine();
            try {
                if (s.length() == 0) {
                    throw new Exception("phai nhap gi do chu nhap lai di");
                }
            } catch (Exception e) {
                System.out.println(e);
                t = 0;continue;
            }
            try {
                m = Integer.parseInt(s);
            } catch (Exception e) {
                System.out.println("nhap so vao");
                t = 0;continue;
            }
            try {
                if (m < 0) {
                    throw new Exception();
                }
            } catch (Exception e) {
                System.out.println("phai nhap so lon hon 0");
                t = 0;
            }
        }
        int a=0;
            try{
            Scanner sc1=new Scanner(new File("long.txt"));
            a=sc1.nextInt();
            System.out.println(a);
            }
            catch(Exception e){}
            System.out.println(a);
        try {
            BufferedWriter bf = new BufferedWriter(new FileWriter("long.txt"));
            bf.write(a);
            bf.write(" "+a);
            bf.newLine();
            bf.write(a);
            bf.close();
            BufferedReader br = new BufferedReader(new FileReader("long.txt"));
        } catch (IOException ex) {
            Logger.getLogger(TryCatch.class.getName()).log(Level.SEVERE, null, ex);
        }
                    
    }    
}
